//
//  CenterVC.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/1/7.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "CenterVC.h"
#import "CenterCollectionCell.h"
#import "centerIcoCollectionCell.h"
#import "PersonInforVC.h"
#import "StudyReportVC.h"
#import "SignUpVC.h"
#import "MyWorkVC.h"
#import "MyInviteVC.h"
#import "MyNewsVC.h"
#import "DeviceVC.h"
#import "NewSetVC.h"
#import "ProtocolVC.h"
#import "MyWorkListVC.h"
#import "AliefuGymVC.h"

@interface CenterVC ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (strong, nonatomic) IBOutlet UICollectionView *left_collectionView;
@property (strong, nonatomic) IBOutlet UICollectionView *right_collectionView;

@end

@implementation CenterVC{
    NSArray *titleArr;//名称
    NSArray *imgArr;//图片
    RequestServices *service;
    NSDictionary *valueDic;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";
    [self.backKuang setHidden:YES];
    [self showBackCenterKuang:[UIImage imageNamed:@"back_center"]];
    [self.left_collectionView registerNib:[UINib nibWithNibName:@"CenterCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"CenterCollectionCell"];
    [self.right_collectionView registerNib:[UINib nibWithNibName:@"centerIcoCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"centerIcoCollectionCell"];
    self.left_collectionView.delegate = self.right_collectionView.delegate = self;
    self.left_collectionView.dataSource = self.right_collectionView.dataSource = self;
    service = [[RequestServices alloc]initWithDelegate:self];
    service.view = self.view;
    [service getUserInfor:8000];
    titleArr = [NSArray arrayWithObjects:@"学习报告",@"我的报名",@"我的作品",@"我的消息",@"我的邀请",@"设备关系",@"安全隐私",@"设置", nil];
    imgArr = [NSArray arrayWithObjects:@"mine_1",@"mine_2",@"mine_3",@"mine_4",@"mine_5",@"mine_6",@"mine_7",@"mine_8",nil];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self HideLoading];
    [service getUserInfor:8000];
}


-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    [self HideLoading];
    if (tag == 8000) {
        valueDic = [NSDictionary dictionaryWithDictionary:obj];
        [self.left_collectionView reloadData];
        [self.right_collectionView reloadData];
    }
}



#pragma mark ----- collectionViewDataSource

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (collectionView == self.left_collectionView) {
        return 1;
    }else{
        return imgArr.count;
    }
}

//每个item的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.left_collectionView) {
        return CGSizeMake(collectionView.frame.size.width, collectionView.frame.size.height);
    }else{
        return CGSizeMake((self.right_collectionView.frame.size.width - 80)/4, self.right_collectionView.frame.size.height*0.5);
    }
}

//cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (collectionView == self.left_collectionView) {
        CenterCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CenterCollectionCell" forIndexPath:indexPath];
        if ([valueDic CheckNSDictionaryData]) {
            cell.dic = valueDic;
        }
        //信息修改
        [cell.change_btn addTarget:self action:@selector(pushPersonInforVC) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
    else{
        centerIcoCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"centerIcoCollectionCell" forIndexPath:indexPath];
        if ([valueDic CheckNSDictionaryData]) {
            [cell.back_view setHidden:NO];
            cell.name_lab.text = [NSString stringWithFormat:@"%@",titleArr[indexPath.row]];
            cell.content_mg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",imgArr[indexPath.row]]];
               }
        return cell;
    }
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.right_collectionView) {
        
        if (indexPath.item == 0) {
            //学习报告
            StudyReportVC *vc = [[StudyReportVC alloc]init];
            [self PushToViewController:vc];
        }else if (indexPath.item == 1){
            //我的报名
//            SignUpVC *vc = [[SignUpVC alloc]init];
            AliefuGymVC *vc = [[AliefuGymVC alloc]init];
            vc.title = @"我的报名";
            [self PushToViewController:vc];
        }else if (indexPath.item == 2){
            //我的作品
            MyWorkListVC *vc = [[MyWorkListVC alloc]init];
            [self PushToViewController:vc];
        }else if (indexPath.item == 3){
            //我的消息
            MyNewsVC *vc = [[MyNewsVC alloc]init];
            [self PushToViewController:vc];
            
        }else if (indexPath.item == 4){
            //我的邀请
            MyInviteVC *vc = [[MyInviteVC alloc]init];
            [self PushToViewController:vc];
        }else if (indexPath.item == 5){
            //设备关系
            DeviceVC *vc = [[DeviceVC alloc]init];
            [self PushToViewController:vc];
        }else if (indexPath.item == 6){
            //安全与隐私
            ProtocolVC *vc = [[ProtocolVC alloc]init];
            [self PushToViewController:vc];
        }else if (indexPath.item == 7){
            //设置
            NewSetVC *vc = [[NewSetVC alloc]init];
            [self PushToViewController:vc];
        }
    }
}

//设置
-(void)setInfor{
    NewSetVC *vc = [[NewSetVC alloc]init];
    [self PushToViewController:vc];
}

//跳转个人详情
-(void)pushPersonInforVC{
    PersonInforVC *vc = [[PersonInforVC alloc]init];
    vc.requestDic = [NSMutableDictionary dictionaryWithDictionary:valueDic];
    [self PushToViewController:vc];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
